package com.qf.qfwemedia.controller.feign;

import com.qf.qfleadnewsfeignapi.wemedia.WmNewsApi;
import com.qf.qfleadnewsmodel.wemedia.pojos.WmNews;
import com.qf.qfwemedia.service.WmChannelService;
import com.qf.qfwemedia.service.WmNewsService;
import com.qf.qfwemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WmNewsApiFeign implements WmNewsApi {

    @Autowired
    private WmNewsService wmNewsService;

    @Autowired
    private WmUserService wmUserService;

    @Autowired
    private WmChannelService wmChannelService;

    @Override
    public WmNews findById(Integer id) {
        return wmNewsService.getById(id);
    }

    @Override
    public String findAuthorNameByAuthorId(Integer id) {
        return wmUserService.getById(id).getName();
    }

    @Override
    public String findChannelNameByChannelId(Integer id) {
        return wmChannelService.getById(id).getName();
    }

    @Override
    public void fillArticleId(String newsId, String articleId) {
        WmNews wmNews = new WmNews();
        wmNews.setId(Integer.parseInt(newsId));
        wmNews.setArticleId(Long.parseLong(articleId));
        //状态修改为9
        wmNews.setStatus((short) 9);

        wmNewsService.updateById(wmNews);
    }
}
